home *** CD-ROM | disk | FTP | other *** search
/ Aminet 48 / Aminet 48 (2002)(GTI - Schatztruhe)[!][Apr 2002].iso / Aminet / util / conv / DCM2ATR.lha / DCM2ATR.doc < prev    next >
Encoding:
Text File  |  2002-01-27  |  23.3 KB  |  399 lines

  1. Atari Diskcomm archive to SIO2PC disk image converter.
  2. Version February 1998.
  3.  
  4. Preface.
  5.  
  6. I think this program hardly needs any introduction.  Or maybe I am
  7. saying this because it is so hard to write one.  I wrote this program
  8. to solve a problem.  I have a relatively large number of Diskcomm
  9. archives, and I need to convert them to SIO2PC archives.  There are
  10. several ways to reach the same goal.  There are several similar
  11. utilities already in existence.  You might ask why I would need to
  12. write yet another one.  Well, I wanted to be sure that these utilities
  13. work the way Diskcomm does.  There are very few people that know
  14. exactly what it is that Diskcomm does, and only if you do have this
  15. knowledge, it is possible to write a utility like this.  If you cannot
  16. be sure about the utilities, you would be forced to use the original.
  17. Since I have the Diskcomm archives on my PC, this involves downloading
  18. them all to our XE, converting them to disks again with Diskcomm, and
  19. copying them back to the PC with a sector copier and SIO2PC.  This
  20. sounded like a lot of work.  I did do this for a couple of them, just
  21. to verify that the resulting disk images were identical to the output
  22. of the utilities.  Since there were differences, I had to come to the
  23. conclusion that these utilities were unreliable.  I also concluded
  24. that I was not going to convert 500+ Diskcomm files by downloading
  25. them.  So I was forced to write something myself.  Time for some
  26. research.
  27.  
  28. I always wanted to know what the specifications for the Diskcomm
  29. format were.  In the near future, we want to be able to convert all
  30. ATR files on our CD to Diskcomm files.  We are not sure that there
  31. will be a lot of people asking for a CD in this format, but several
  32. people have told us that they would not be interested in a CD unless
  33. it was in the Diskcomm format.  To be able to do this, you need to
  34. know the format.  As we all know, Bob Puff wrote Diskcomm, so we asked
  35. him for the specs.  Clear thinking.  Unfortunately, he is very busy.
  36. And if you write tools like these, you just write the program, without
  37. first writing down the specs.  You make them up as you go along.  So
  38. he would have to sit down and write them up.  Well, at this point I
  39. had several good reasons for wanting to have the format specifications
  40. right away.  So I had to start a reverse engineering project to figure
  41. out the format.  This has been done before.  Jason Duerstock started
  42. to figure it all out by trying to convert various diskettes to
  43. archives, and then determined what it was that Diskcomm stored in the
  44. archive.  He also wrote the first conversion program.  He did a nice
  45. job, and wrote down some specs.  He even shared them with others, so
  46. now there are several of these programs.  Unfortunately, he did make
  47. some minor mistakes.  Other people discovered some of them, and
  48. corrected these.  But there are still some undiscovered problems, as
  49. the comparison with the real Diskcomm output proved.  I took a
  50. different approach.  I disassembled the code.  Now this is not a
  51. simple task, mainly because it costs a lot of time.  On the other
  52. hand, I have done this a lot, so within several weeks, I sort of had a
  53. source code listing, that I could start to interpret.  There are a lot
  54. of hours in a week if you do not sleep.  And even then there are too
  55. few.  But in the end, you can simply see what it is that Diskcomm
  56. does, so at a certain point, you can guarantee that what your program
  57. is doing is correct.  I discovered that the current version of
  58. Diskcomm supports an older version of Diskcomm.  It will not create
  59. archives in this format anymore itself though.  So this is something
  60. one would never have been able to find out with other methods of
  61. reverse engineering.
  62.  
  63. Purpose of this project.
  64.  
  65. The design goal of this project is to have a way of converting
  66. Diskcomm archives to SIO2PC diskette image files, on the system that
  67. uses these images.  Another goal of this project is to finally
  68. document the format of Diskcomm archive files.  This opens up the way
  69. for more utilities.
  70.  
  71. Theory of operation.
  72.  
  73. People wanted to be able to transmit programs over telephone lines.
  74. Almost all communications programs are capable of transmitting files
  75. with a modem.  However, on the Atari, lots of programs were designed
  76. as a bootable disk.  The programs on bootable disks cannot be easily
  77. transmitted with these communications programs.  So there was a need
  78. to convert bootable disks to a format that can be transmitted.
  79. Diskcomm was written for this purpose.  It is designed to convert the
  80. data on a diskette into some format that can be transmitted with a
  81. communications program.  After transmitting it, the data must be
  82. written to a diskette again, and thus effectively the contents of the
  83. diskette are transported across many miles instantly.  That is what
  84. tele-communications is all about.  So Diskcomm simply reads a disk
  85. sector by sector, and stores the data it finds in a big file, that
  86. holds the contents of all the sectors on the disk.  After this file
  87. has been transmitted, it can be written to the diskette at the
  88. receiver location.  So Diskcomm is in fact really only a sector copier
  89. by modem.  This sounds simple, but life just isn't simple sometimes.
  90. One problem you would encounter is that when DOS stores files on a
  91. disk, it adds some overhead to keep track of the data, and the
  92. available space on the disk.  Now if you are going to copy all sectors
  93. on the disk, and add some overhead to this, then it is clear that you
  94. will not be able to write a file that big to a single diskette.  It is
  95. obvious that this will not work.  Well, one solution is to cut the
  96. file in half.  Simply write the first half of the disk to one file,
  97. and the second half to another, using another diskette.  This means
  98. you will have to transmit two files, and at the receiver side, you
  99. would need to write the data of both these files to the diskette.
  100. This is a bit inconvenient, but not a big problem.
  101.  
  102. Of course, there are other ways of solving this problem.  How about
  103. figuring out some way of compressing the data?  If you can reduce the
  104. amount of bytes that is needed to represent the contents of the
  105. diskette, you might be able to store all data in one file, and have it
  106. fit onto a diskette even with the added overhead.  This would make the
  107. process of transmitting disks a lot easier.  You already figured out
  108. that Diskcomm does some compressing of course.  The typical Diskcomm
  109. archive file is some 10 percent smaller than the size of the disk.
  110. This may not seem much, but it is sufficient for the purpose of
  111. reducing it by enough to make it fit on a diskette.  Remember that the
  112. current version of Diskcomm is dated December 1987, so the more
  113. elaborate compression algorithms were not invented yet.  There are
  114. disks that are compressed rather well, so it varies by content.  The
  115. current version of Diskcomm tries a couple of tactics.  All
  116. compression is done on a sector basis.  It tries to detect
  117. repetitions.  For instance, if two consecutive sectors have an
  118. identical content, the data is not stored twice, but Diskcomm stores
  119. an indicator to flag that the contents of the next sector are
  120. identical to the previous one.  This saves a lot of space in the
  121. archive.  Or when a sector contains similar bytes, the bytes are
  122. replaced by an indicator that represents the number of repetitions.
  123. Of course this again adds some overhead, since now instead of simply
  124. storing all sectors in a file, you also have to store the compression
  125. type applied to that sector.  In the end, this extra overhead is
  126. negligible compared to the amount of space saved by the compression.
  127. Another type of reducing the data is simply leaving sectors out.  Most
  128. diskettes have at least a couple of sectors that are unused.  These
  129. sectors contain nothing but zeroes.  We can simply leave these out,
  130. without losing any data.  Of course this means that we have to keep
  131. track of what sector to write and what sector to skip when we are
  132. writing to the diskette again.  All this compressing makes the process
  133. a bit more complicated when we want to copy the data back to the
  134. diskette.  But that is not a problem, if we know what types of
  135. compression to expect.  Well, we have talked about this issue before.
  136.  
  137. Now what happens if the data on the diskette is such that there are no
  138. similar sectors?  And if we try the other compression algorithms, what
  139. if it is simply impossible to compress the data?  Then the added
  140. overhead will make the file even grow larger.  So it is obvious that
  141. we have to combine the two techniques.  If we discover that the
  142. archive file does not fit onto one diskette, we have to split up the
  143. archive into multiple smaller archive files.  It is hard to tell up
  144. front what to do, so most of the time, we simply rely on the
  145. compression, and hope that it will fit.  If it doesn't, we will have
  146. to start over and create multiple smaller archive files.
  147.  
  148. Most of you already know all this of course.  I just wanted to sum
  149. this up, so that we all know what we are talking about.  As can be
  150. expected, to organize all this compressing and splitting up, we need
  151. some control information to prevent the user of the Diskcomm program
  152. from making mistakes.  Some information needs to be added to the
  153. archive file to indicate that the archive file was split up into
  154. multiple files.  Also, some information about the diskette type would
  155. be useful, since we might have to format the output diskette before
  156. writing the sectors to it.
  157.  
  158. Well, enough of this techno-talk.  Since this project had two goals, I
  159. will write two separate documents.  One for the people that just want
  160. to use this utility, and one for the people that are interested in the
  161. structure of Diskcomm archives.  The other document is included in
  162. this package too.  It is the source code.  If you can read 'C' code,
  163. you can see what the format of a Diskcomm archive is.  If I have some
  164. more time, I might write an English version, but for now the source
  165. will have to do.  For people that want to run this program on some
  166. other platform, you should be able to compile the source on any
  167. platform without problems, since it only uses standard 'C' stuff.
  168. Well, as usual the Atari ST has some problems with command line stuff,
  169. but if you write programs on the ST, you should know how to deal with
  170. this.  I consider this source code to be public domain.  Use whatever
  171. you want to write your own utility.  I will retain the copyright to
  172. the program name, so you will have to give your program a different
  173. name.  If you want to use this program as a basis for a utility with a
  174. completely different purpose this should not be a problem.  I just
  175. want people to know which program I wrote.  If you only want to port
  176. it to another system, using the same file name, feel free to do so,
  177. and post your results.  Please include the documentation in this case.
  178. However if you want to change the program substantially, use a
  179. different name.  If you discover bugs in the PC version, report them
  180. to me, so that I will be able to fix them and release a new version.
  181. I do have compilers for the Macintosh and the ST, but I have limited
  182. time, so let other people join the fun if they have some more time.
  183.  
  184. The output.
  185.  
  186. During the development stage, I had the program print a lot of
  187. information to the screen.  As usual, printing to the screen makes the
  188. information scroll by faster than you can read, so I redirected the
  189. output to a file.  All the relevant data can then be examined at your
  190. own pace.  This data is only important if there is a bug in my
  191. program, and you want to be able to fix it.  Well, if the archive has
  192. been damaged, you might also be able to determine what is wrong with
  193. the file.  Not that this would help you a lot though.  If you want to
  194. see this diagnostic data, you can make the program print it by using
  195. the command line switch or by responding with yes if the program asks
  196. for this option.  When the conversion process is complete, the program
  197. will print statistics about the Diskcomm file processed, if so
  198. requested.  The program prints the number of headers encountered.  For
  199. archives that have been created as one large file, we will encounter
  200. one or more FA type headers.  For archives that have been created as
  201. multiple smaller files, we will encounter several F9 type headers.
  202. For each type of compressed sector the program counts the number of
  203. times that this type of compression occurs in the archive.  This is
  204. printed, as is the total number of compressed sectors.  Sectors that
  205. are completely filled with zeroes are not stored in the archive, so
  206. they cannot be counted.  We do know how many sectors we created in the
  207. output file, so this can be printed.  If we subtract the total count
  208. from the total number of sectors, we know how many sectors were empty.
  209. All this information is not really important, but it is fun to know.
  210. The count of the flush buffer codes should be equal to the count of
  211. headers encountered.  Again, this is not really important.
  212.  
  213. Command line options.
  214.  
  215. Running the DCM2ATR program is easy.  You have two options.  You can
  216. run it interactively, by simply starting it.  It will ask for the
  217. filename of the Diskcomm archive file.  Once that is entered, it will
  218. ask you to enter the filename for the SIO2PC disk image file to be
  219. created.  Next, you can specify whether or not you want the
  220. diagnostics to be printed.  If you wish this data to be printed, it
  221. will be printed to the screen.  The output can be redirected to a file
  222. using the standard DOS redirection, but that would redirect the
  223. prompts to the redirected output too, so this is only recommended if
  224. you use the command line arguments.  You are then asked to enter
  225. whether or not you want to see the statistics for the Diskcomm
  226. archive.  This will produce a list of the number of blocks encountered
  227. for each compression type.  Then you are asked to enter the highest
  228. sector number.  If this is a standard diskette, simply press return.
  229. Otherwise enter the number of sectors that are available on the type
  230. of diskette you are processing.  You can enter all this on the command
  231. line if you prefer.  The printing of diagnostic data is an option
  232. switch, which can be selected by adding /d to the command.  The
  233. printing of the statistics can be selected by adding /s to the
  234. command.  The Diskcomm archive file to process is the first argument
  235. on the command line.  The filename for the SIO2PC disk image file is
  236. optional, and if it is present, it is the second argument.  If it is
  237. omitted, the input file is assumed to have a .DCM extension.  This
  238. extension will be replaced by the .ATR extension.  The resulting
  239. filename is then used to create the SIO2PC disk image file.  So if we
  240. want to process a file named demo.dcm in the \xl_dcm directory, we
  241. would enter:
  242. dcm2atr /d /s \xl_dcm\demo.dcm \xl_atr\demo.atr > demo.txt
  243. This would select the printing of diagnostic data, redirecting it to
  244. the file demo.txt in the current directory.  After successful
  245. conversion, statistics about the conversion process are printed.
  246. Since all output is redirected, this too will be stored in the file
  247. demo.txt.
  248.  
  249. If the Diskcomm archive file is created from a disk of non-standard
  250. size, we will have to enter the highest sector number to expect.  This
  251. is option H in the Diskcomm program.  For this program, it is only
  252. used to append empty sectors to the end of the disk image.  If the
  253. original disk contained 1440 sectors, the Diskcomm archive will simply
  254. contain that many sectors, unless the last sectors contain zeroes.
  255. For most applications, this is not a problem.  If the programs on the
  256. disk do not need these sectors, and you are not going to write to the
  257. disk image, you do not need these extra sectors.  On the other hand,
  258. if you want to be able to make modifications, you have to have these
  259. sectors available.  In this case, you must tell this program what the
  260. highest sector number is, using the /h command switch.  After the /h,
  261. you have to specify the number in decimal notation.  For 1440 sectors,
  262. you would have to enter /h=1440.  The program will then make sure that
  263. there are at least 1440 sectors in the file.  This option cannot be
  264. used to truncate a file, since we will always process all the sectors
  265. that are in the Diskcomm archive.  It only tells the program the
  266. minimum amount of sectors.  This option is not needed for archive
  267. files created from standard diskettes.  For a normal single density
  268. disk, it is assumed that it contains 720 sectors.  Enhanced density
  269. disks are assumed to contain 1040 sectors.  Double density disks are
  270. assumed to have 720 sectors.  Note that on all Atari double density
  271. disks, the first three sectors are always only 128 bytes, while the
  272. rest contain 256 bytes.  This is only important if you compute the
  273. size of the SIO2PC disk image file.  The program does this for you,
  274. and it stores this information in the header of the disk image.  If
  275. you want to overrule the standard sizes, to save disk space for
  276. instance, you could use this to force this program to not append any
  277. unused sectors at the end by specifying a value of 1.  So this might
  278. truncate the disk image a little.  So I lied.  Anyway, you can only
  279. control the number of sectors that contain zeroes.  Note that adding
  280. extra sectors beyond the original number of sectors of the disk does
  281. not make more space available on the disk image, since the VTOC and
  282. other DOS information on the disk is not modified accordingly.  If
  283. your program handles all sector I/O itself though, this can be used
  284. to make the disk bigger.  But you can create a large disk with SIO2PC
  285. itself, so you do not need this program for that.
  286.  
  287. Multi file archives.
  288.  
  289. Like we already discussed, some disks need to be split into several
  290. smaller archive files.  This program is kept relatively simple, so it
  291. simply does not handle multi file archives the way Diskcomm does.  I
  292. could have added that, but that would only cost me extra time.  The
  293. current version of this program does convert the Diskcomm archive
  294. files properly, so I reached my goal.  Other people are very welcome
  295. to enhance this program, I do not have a need for more functionality.
  296. Besides, I also do not have the time for it.  We have a CD to finish.
  297. When Diskcomm converts an archive to a diskette, it will know that
  298. this is a multi file archive, because the first byte will contain F9.
  299. It will then ask what byte of the filename is to be incremented when
  300. the end of the file has been reached.  To keep this program simple, we
  301. will assume that the last byte of the file name portion will be
  302. incremented.  This must be a "1" or an "A".  It will scan the filename
  303. until it finds either a "1" or an "A".  When the program cannot find
  304. either of these, the last byte before the extension is incremented.
  305. This byte will then be incremented for each file that is processed.
  306. If there is only one file, no incrementing is needed of course.
  307.  
  308. You can convert a multi file archive into a single file archive by
  309. merging all parts of the archive.  This is very easy, most systems
  310. have some way of concatenating multiple files into one file.  On a DOS
  311. PC, this can be done with the copy command.  Suppose you have an
  312. archive that consists of three files: demo1.dcm, demo2.dcm and
  313. demo3.dcm.  To merge these files enter:
  314. copy /B demo1.dcm + demo2.dcm + demo3.dcm demo.dcm
  315. to create a single file archive.  The /B switch is required to make
  316. DOS treat the file as a binary file, so that it does not treat the
  317. hexadecimal value 1A as an end of file marker.  You could try using
  318. wild cards:
  319. copy /B demo?.dcm demo.dcm
  320. but this will give you some weird error message.  That is because this
  321. will cause the resulting demo.dcm file to be concatenated too.  So you
  322. would have to give it a different name, or specify a different
  323. directory.  But even then, if the files are not concatenated in the
  324. proper order, you will not be able to convert the archive into a disk
  325. again.  DOS does not sort files by filename, so using wild cards is
  326. not recommended.  There is a big chance that the files will not be
  327. processed in the proper order.  If you do use wild cards, make sure
  328. you pay attention to the sequence in which the files are processed.
  329. Enter all files in the proper order on the command line for copy if it
  330. does not copy the files in the proper order. Refer to your system's
  331. manual if you need more information.
  332.  
  333. Troubleshooting.
  334.  
  335. If a Diskcomm archive cannot be converted to a SIO2PC disk image,
  336. there are very few things you can do about it.  Maybe the file was not
  337. properly uploaded or downloaded.  Sometimes, uploading or downloading
  338. a file may add extra bytes to a file.  The program tries to detect
  339. this.  After a flush buffer code, the program starts looking for a
  340. header byte again.  Any junk that is found is simply discarded.  This
  341. should take care of the problem.  However, if the file is damaged,
  342. because some sort of transmission or conversion error, we will most
  343. likely not be able to use it.
  344.  
  345. Some errors might occur with multi file archives.  When the end of a
  346. file has been reached, the program will attempt to open another file,
  347. if the last pass of the archive has not been processed yet.  So the
  348. current Diskcomm archive file is closed, the character that we decided
  349. to use to increment is then incremented, and we will try to open the
  350. next part of the archive.  All sorts of things can go wrong here, but
  351. these problems are easy to diagnose.  First off, the next file must be
  352. present.  If the character that we should be incrementing is not the
  353. last character in the filename, as described before, then this program
  354. will not be able to process this set of files.  Either merge the
  355. archive files, or rename the files such that there is a "1" or an "A"
  356. in the last position.  You would have to rename all portions
  357. accordingly of course.  If for some reason the sequence of the files
  358. is not correct, the program will tell you that the pass number is out
  359. of sequence.  Check and correct the filenames.  If you merged a multi
  360. file archive, you might have merged them in an incorrect order,
  361. possibly because you used wild cards.  If you merged the archive
  362. files, processing can continue without closing and opening of the next
  363. file of course.
  364.  
  365. I cannot think of any more problems.  If you are reading this, it
  366. might mean you now have a problem that I have no solution for.  Who
  367. else would read the documentation?  You might try getting help from
  368. the newsgroup, or send me an E-mail.
  369.  
  370. Epilog.
  371.  
  372. Well, reading the manual wasn't that hard now was it?  I have stated
  373. that some of the other similar utilities that exist in their current
  374. version will not always convert a Diskcomm archive properly.  I am not
  375. accusing anyone.  I just want you all to know that if you have tried
  376. utilities like this before, that the disk images that were produced
  377. might have been faulty.  If this lead you to believe that this sort of
  378. thing does not work, you might want to try it again.  What I am more
  379. concerned about though is that if you used these utilities before, you
  380. might now have several disk image files that are corrupted.  If you
  381. still have the Diskcomm files, you should probably convert them all
  382. over again, to make sure that the disk image contains the data that it
  383. is supposed to.  Well, that is about it.  Thanks to Bob Puff for
  384. inventing Diskcomm.  Thanks to Nick Kennedy for inventing SIO2PC.
  385. Thanks to Jason Duerstock and all others that thought of bridging the
  386. gap, like Bobterm says, in more than one way.  This includes Steven
  387. Tucker for inventing Imagic and APE, thanks for updating your stuff
  388. too, for people that do not know how to handle a command line.  Thanks
  389. to you for still caring.  This program is totally free.  If you want
  390. to get rid of some money, the afore mentioned people worked hard to
  391. make this all possible, so maybe it is time to pay that shareware fee.
  392. Keep those XL's/XE's humming.
  393.  
  394. Ernest R. Schreurs
  395. Kempenlandstraat 8
  396. 5211 VN  Den Bosch
  397. The Netherlands
  398. E-mail: ernest@wxs.nl
  399.